//
//  HomeSegDataSource.swift
//  LeGou
//
//  Created by lxm on 2022/9/19.
//

import UIKit
import JXSegmentedView

class HomeSegDataSource: JXSegmentedBaseDataSource {
    
    var datas = [(String, String)]()
    
    override func registerCellClass(in segmentedView: JXSegmentedView) {
        segmentedView.collectionView.register(HomeSegCell.self, forCellWithReuseIdentifier: "HomeSegCell")
    }
    
//    override func itemDataSource(in segmentedView: JXSegmentedView) -> [JXSegmentedBaseItemModel] {
//        return dataSource
//    }
    
    override func segmentedView(_ segmentedView: JXSegmentedView, cellForItemAt index: Int) -> JXSegmentedBaseCell {
        let cell = segmentedView.dequeueReusableCell(withReuseIdentifier: "HomeSegCell", at: index)
        return cell
    }
    
//    referredSegmentedView(_ segmentedView: JXSegmentedView, widthForIte
    
    override func preferredSegmentedView(_ segmentedView: JXSegmentedView, widthForItemAt index: Int) -> CGFloat {
        rpx(50)
    }
    
//    preferredItemCount
    override func preferredItemCount() -> Int {
        return datas.count
    }
    
    /// 子类需要重载该方法，用于返回自己定义的JXSegmentedBaseItemModel子类实例
    override func preferredItemModelInstance() -> JXSegmentedBaseItemModel  {
        return HomeSegModel()
    }
        
    
    open override func preferredRefreshItemModel(_ itemModel: JXSegmentedBaseItemModel, at index: Int, selectedIndex: Int) {
        super.preferredRefreshItemModel(itemModel, at: index, selectedIndex: selectedIndex)

        guard let itemModel = itemModel as? HomeSegModel else {
            return
        }
        itemModel.topTitile = datas[index].0
        itemModel.bottomTilte = datas[index].1
    }
    
}
